package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class Usercontroller {

    //这里是user表的注册功能  注册就是添加，这里先需要查询出表里的用户名称，然后根据拿用户名去比较，
    //不等于空的并且用户是普通成员的直接返回到

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(User user, HttpServletRequest request, HttpSession session) {
        User user1 = userService.selectByNAame(user);
        if(user1!=null){
            if(user1.getOid()==1){
                String username = request.getParameter("username");
                session.setAttribute("username",username);
                return  "redirect:/etc/findAll";
            }else {
                String username = request.getParameter("username");
                session.setAttribute("username",username);
                return  "redirect:/etc/selectAll";
            }

        }else {
            return "login";
        }
    }

    //注册 点击注册进入前台注册页面
    @RequestMapping("zhuce")
    public  String zhuce(){
        return "addUser";
    }
    //注册就是添加，添加方法  注册完成返回登录页面
    @RequestMapping("insertUser")
    public  String insertUser(User user){
        userService.insertUser(user);
        return "login";
    }





}
